package com.shop.product.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.shop.product.vo.ProductVO;

@Repository
public class ProductTagDAOImpl extends SqlSessionDaoSupport implements ProductTagDAO {

	@Override
	public int totalCnt() {
		return (Integer)getSqlSession().selectOne("com.shop.product.tag.totalCnt");
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public List<ProductVO.ProductTag> listTag(int current_page, int list_row_no) {
		
		// 페이징 관련
		int start_row_index = (current_page -1) * list_row_no;
		int end_row_index = list_row_no;
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("start_row_index", start_row_index);
		paramMap.put("end_row_index", end_row_index);
		
		return getSqlSession().selectList("com.shop.product.tag.list", paramMap);
	}
	
	@Override
	public int addTag(ProductVO.ProductTag tagItem) {
		getSqlSession().insert("com.shop.product.tag.add", tagItem);
		return tagItem.getSeq();
	}
	
	@Override
	public void updateTag(ProductVO.ProductTag tagItem) {
		getSqlSession().update("com.shop.product.tag.update" ,tagItem);
	}
	
	@Override
	public void deleteTag(int seq) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("seq", seq);
		getSqlSession().delete("com.shop.product.tag.delete", paramMap);
	}
	
	@Override
	public ProductVO.ProductTag getTag(int seq) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("seq", seq);
		return (ProductVO.ProductTag) getSqlSession().selectOne("com.shop.product.tag.get", paramMap);
	}
}
